package cn.le.kafka;

import cn.le.bean.dto.MsgPointDTO;
import cn.le.bean.enums.EnumKafkaTopic;
import cn.le.bean.vo.NettyMsg;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;

import javax.annotation.PostConstruct;

/**
 * kafka 发送im消息
 */
class KafkaImUtils {

    private static KafkaImUtils INSTANCE;

    @Autowired
    private KafkaTemplate kafkaTemplate;

    public static void sendMsg(NettyMsg msg){
        INSTANCE.kafkaTemplate.send(EnumKafkaTopic.im_msg, JSONObject.toJSONString(msg));
    }
    public static void sendReply(NettyMsg msg){
        INSTANCE.kafkaTemplate.send(EnumKafkaTopic.im_reply,JSONObject.toJSONString(msg));
    }
    public static void sendOffline(NettyMsg msg){
        INSTANCE.kafkaTemplate.send(EnumKafkaTopic.im_off_line,JSONObject.toJSONString(msg));
    }

    @PostConstruct
    private void setUp() {
        INSTANCE = this;
    }

}
